<template>
  <div class="app-container">

    <div style="margin-bottom:5px">
      <el-input v-model="searchTitle" placeholder="请输入要查找的试卷" size="small" style="width:30%"/>
      <el-button type="primary" size="small" @click="fetchData(0)">查找</el-button>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
      size="small"
      @selection-change="handleSelectionChange">
      <el-table-column align="center" label="ID" width="45">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="试卷">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column label="交卷人" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.createBy }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="created_at" label="答卷时间" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time"/>
          <span>{{ currentDateTime }}</span>
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" label="" width="110" align="center">
        <template slot-scope="scope">
          <router-link :to="{ path: '/test', params: { id: 123 }}">
            <el-button type="primary" size="small">阅卷</el-button>
          </router-link>

        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :page-size="pageSize"
      :total="total"
      background
      layout="prev, pager, next"

      @current-change="handleCurrentChange"/>
  </div>
</template>

<script>
import { getList } from '@/api/userTest'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        1: '选择题',
        2: '主观题'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      searchTitle: '',
      list: null,
      listLoading: true,
      total: 0,
      pageSize: 20,
      currentDateTime: new Date(),
      multipleSelectionAll: [], // 所有选中的数据包含跨页数据
      multipleSelection: [] // 当前页选中的数据
    }
  },
  created() {
    this.fetchData(0)
  },
  methods: {
    fetchData(currentPageNum) {
      this.listLoading = false
      getList(this.searchTitle, currentPageNum, 20).then(resp => {
        this.list = resp.data
        this.total = resp.total
        this.pageSize = resp.pageSize
      })
      // getList(this.listQuery).then(response => {
      //   this.list = response.data.items
      //   this.listLoading = false
      // })
    },
    handleCurrentChange(currentPageNum) {
      this.fetchData(currentPageNum)
    },
    handleSelectionChange(val) {
      // this.multipleSelection = val;
      console.log(val)
    }
  }
}
</script>
